<?php

namespace Admin\Controller;


use Admin\Common\Page;

class LogBrokenController extends BaseController{

    public function index(){
        $map = [];
        $order_id = I('get.order_id');
        if (!empty($order_id)) {
            $map['a.order_id'] = $order_id;
        }

        $pay_id = I('get.pay');
        if (!empty($pay_id)) {
            $map['a.pay_id'] = $pay_id;
        }

        $interval_time = I('get.interval_time');
        if (!empty($interval_time)) {
            $time=explode('~',$interval_time);
            $time[0]=$time[0].' 00:00:00';
            $time[1]=$time[1].' 23:59:59';
            $map['a.create_time'] = [
                ['gt',$time[0]],
                ['lt',$time[1]]
            ];
        }
        $count = M('order_broken')->alias('a')->where($map)->count();// 查询满足要求的总记录数
        $Page = new  \Admin\Common\Page($count, C('page.size'));// 实例化分页类 传入总记录数和每页显示的记录数(25)
//        $Page = new  \Admin\Common\Page($count, 5);// 实例化分页类 传入总记录数和每页显示的记录数(25)
        $show = $Page->show();// 分页显示输出
        $this->assign('page', $show);// 赋值分页输出

        $data = M('order_broken')->alias('a')
            ->join("left join book b on a.book_id=b.book_id")
            ->join("left join card c on a.user_id=c.user_id")
            ->join("left join pay d on a.pay_id=d.pay_id")
            ->where($map)
            ->limit($Page->firstRow . ',' . $Page->listRows)
            ->field('
                a.order_broken_id,a.order_id,a.money,a.money_original,a.state_order,a.create_time,
                b.sm,b.spbs,b.tm,
                c.card_id,
                d.way
            ')
            ->select();



        if(I("get.execl")==1){
            $file = excel_export($data);
            ouput_Browser($file);
        }else{
            $this->data = $data;
            $this->display();
        }
    }
    
}